import java.util.function.DoubleBinaryOperator;

/**
 * @ClassName: LambdaDemo
 * @Author: liugui
 * @Date: 2021-08-03 14:31
 **/
public enum Operation {

    PLUS ("+", (x,y)->x+y),
    MINUS("-", (x,y)->x-y),
    TIMES("*",(x,y)->x*y),
    DIVIDE("/",(x,y)->x/y);

    private final String symbol;
    private final DoubleBinaryOperator op;
    Operation(String symbol, DoubleBinaryOperator operator) {
        this.symbol = symbol;
        this.op = operator;
    }

    @Override
    public String toString() {
        return "Operation{" +
                "symbol='" + symbol + '\'' +
                '}';
    }

    public String getSymbol() {
        return symbol;
    }

    public  double apply(double x,double y){
        return op.applyAsDouble(x,y);
    }
}
